new Vue({
    el: '#app',
    data() {
      return {
        form: {
          Enterprise_Info_SerialNumber: $.cookie('enterprise'),
          Contract_Table_Name: '',
          page: 1,			//页数
          limit: 10			//每页数据条数
        },
        tableData: [],		//表格数据
        total: 1,
        loading: false
      }
    },
    mounted() {
      this.getList(this.form)
    },
    methods: {
      onSerach() {				//查询方法
        this.form.page = 1
        this.getList(this.form)
      },
      handleSizeChange(val) {
        this.form.page = 1;
        this.form.limit = val;
        this.getList(this.form)
      },
      handleCurrentChange(val) {
        this.form.page = val;
        this.getList(this.form)
      },
      getList(data) {     //换页方法
        let _this = this
        $.ajax({
          type: 'POST',
          url: DomainName + "/getContractTableAction?token=" + $.cookie('token'),
          data,
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          },
          success: function (Result) {
            Result.tableData.forEach(item => {
              item['Children'] = {
                contract_template_detail:[]
              }
            });
            console.log(Result.tableData);
            _this.tableData = Result.tableData      //将获取的数据存到表格数据中
            _this.total = Number(Result.limit)
          },
          dataType: "json"
        });
      },
      handleChildren(row){//展开
        _this = this
        if (!row.Children.contract_template_detail.length) {
          $.ajax({
            url: DomainName + '/getInquiryIDAction?token='+$.cookie('token'),
            type: 'POST',
            data: {
              Data: 'contract_table',
              Primary_Key:row.Contract_Table_SerialNumber,
              Primary_Key_Name:'Contract_Table_SerialNumber',
              isNullEnterprise:true,
            },
            success: function (data) {
              row.Children.contract_template_detail = data;
            },
            dataType: "json"
          });
        }
      },
      Add() {
        window.location.href = './Add.html'
      },
      Show(Contract_Template_URL){
        sessionStorage.setItem("Contract_Template_URL", Contract_Template_URL)
        window.open('./Show.html?Contract_Template_URL=' + Contract_Template_URL)
      },
      Delete(Contract_Template_SerialNumber) {
        const _this = this
        this.$confirm('警告！此操作将删除此合同模板, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          $.ajax({
            url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
            type: 'POST',
            data: {
              TableName: 'contract_template',
              Primary_Key: Contract_Template_SerialNumber,
              Primary_Key_Name: 'Contract_Template_SerialNumber',
              Operation_Name: '删除合同模板'
            },
            success: function (res) {
              if (res.Status == 'success') {
                _this.getList(_this.form);
                _this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              }
            },
            complete: function (XMLHttpRequest) {
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        }).catch(() => {
          this.$message({
            type: 'warning',
            message: '已取消删除'
          });
        });
      },
    },
  })